import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import { staticPaths } from './config.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const app = express();
const PORT = 8888;

// 注册静态资源路由
staticPaths.forEach(({ path: urlPath, dir }) => {
    // 基本路径
    app.use(urlPath, express.static(path.join(__dirname, dir)));
    // 双重路径（处理publicPath配置）
    app.use(`${urlPath}/${dir}`, express.static(path.join(__dirname, dir)));
});

app.listen(PORT, () => {
    console.log(`服务器运行在 http://localhost:${PORT}`);
});